package se.teamscape.client.presenter;

import net.customware.gwt.presenter.client.EventBus;
import se.teamscape.client.controller.AppController;
import se.teamscape.client.place.BasicPlaceManager;
import se.teamscape.client.place.ListTeamsPlace;

import com.google.inject.Inject;

/**
 * Presenter that handles navigation.
 * It is up to the view to present the links
 * in a category format.
 * 
 * @author Andreas Borglin
 * 
 */
public class NavigationPresenter extends BasePresenter<NavigationPresenter.Display> {

    public interface Display extends BasePresenter.Display {
        void addCategory(String name, boolean expanded);

        void addLink(String category, String name, String token);
    }

    @Inject
    public NavigationPresenter(Display display, EventBus eventBus) {
        super(display, eventBus);
    }

    @Override
    protected void onLazyBind() {

    }

    @Override
    protected void onRevealDisplay() {

        if (needsUpdate()) {
            setupLinks();
            viewUpdated();
        }

    }

    private void setupLinks() {

        String general = AppController.getConstants().general();
        display.addCategory(general, true);

        display.addLink(general, AppController.getConstants().listTeams(), BasicPlaceManager
                .toHistoryToken(ListTeamsPlace.NAME));

    }

}
